package member.api;

import member.api.vo.MemberVo;
import member.model.core.CoreUser;
import member.model.core.CoreUserExt;
import member.model.shop.Member;
import member.model.shop.MemberGroup;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import utils.sql.PageVo;

import java.util.Date;
import java.util.List;

/**
 * Created by xiaoqian on 2016/10/8.
 */
public interface MemberApi {

    public String toString();

    /**
     * 创建用户
     * @param coreUser
     * @return
     */
    public CoreUser createUser(CoreUser coreUser);

    /**
     * 更新用户数据，每次只能更新一项关键数据项，同时要校验填写旧数据是否正确
     * @param userId
     * @param oldPassword
     * @param newPassword
     * @return
     */
    public CoreUser UpdateUserPassword(String userId,String oldPassword,String newPassword);

    /**
     *
     * @param userId
     * @param oldEmail
     * @param newEmail
     * @return
     */
    public CoreUser UpdateUserEmail(String userId,String oldEmail,String newEmail);


     /**
     *
     * @param userId
     * @param oldPhone
     * @param newPhone
     * @return
     */
    public CoreUser UpdateUserPhone(String userId,String oldPhone,String newPhone);

    /**
     * 创建新会员
     * @param coreCompanyId
     * @param coreUser
     * @param member
     * @return
     */
    public boolean createMember(String coreCompanyId, CoreUser coreUser, Member member, CoreUserExt coreUserExt);

    /**
     * 更新会员信息
     * @param member
     * @return
     */
    public Member updateMember(Member member);

    /**
     * 取用户信息
     * @param coreUserId
     * @return
     */
    public CoreUser getUserInfo(String  coreUserId);

    /**
     * 取会员信息
     * @param memberId
     * @return
     */
    public MemberVo getMemberInfo(String  memberId);

    /**
     * 取会员信息
     * @param userId
     * @return
     */
    public MemberVo getMemberInfoByUserId(String  userId);

    /**
     * 取会员信息
     * @return
     */
    public MemberVo getMemberInfoByUserPhone(String  phone);

    /**
     * 获取SSO统一登录导入用户，只需提供某个参数即可，其余参数传null，多个参数时查询条件优先级 uid > email > mobile > name
     * @param uid
     * @param email
     * @param mobile
     * @param name
     * @return
     */
    public MemberVo getSsoMemberInfo(String uid, String email, String mobile, String name);

    /**
     * 查询系统中定义的所有的有效会员组
     * @return
     */
    public List<MemberGroup> listAllMemberGroup();

    /**
     * 根据CoreUser取会员信息
     * @param coreUser
     * @return
     */
    public Member getMemberInfoByCoreUser(CoreUser coreUser);

    /**
     * 分页取用户信息
     * @param pageRequest
     * @return
     */
    Page<Member> getMemberPage(PageRequest pageRequest);

    Page<Member> listMembers(Date startDate, Date endDate, String name, String type, String company, Pageable pageable);

    /**
     * 根据organizationId查询member
     * @param organizationId
     * @return
     */
    public List<Member> findMemberByOrganizationId(String organizationId);

    /**
     * 根据id查询member
     * @param id
     * @return
     */
    public Member findMemberById(String id);

    public List<Member> findMembersByCoreUsers(List<CoreUser> coreUser);

    public Member saveMember(Member member);

    public Page<Member> findMemberByParams(String username, String companyId, String organizationId, Pageable pageable);

    public PageVo findMemberPageByUserIdAndName(int pageSize, int pageNum, String userId, String searchLoginId, String memberName);

    /**
     * 根据Example实体查找
     * @param example
     * @return
     */
    public List<Member> findMemberByExample(Member example);

    /**
     * 根据Example实体查找(结果分页)
     * @param example
     * @param pageable
     * @return
     */
    public Page<Member> findMemberByExample(Member example, Pageable pageable);

    public List<Member> findByUsers(List<CoreUser> users);
}
